﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace PublicComputerLogoffApplication
{
    public static class UserLogoff
    {
        [DllImport("User32.dll")]
        public static extern bool ExitWindowsEx(ExitWindowsFlags uFlag, UInt32 dwReserved);

        public static bool ExitWindowsEx(ExitWindowsFlags uFlag)
        {
            return ExitWindowsEx(uFlag, 0);
        }

        public static void LogoffUser()
        {
            ExitWindowsEx(ExitWindowsFlags.EWX_LOGOFF);
        }

        [Flags]
        public enum ExitWindowsFlags
        {
            EWX_LOGOFF = 0,
            EWX_SHUTDOWN = 0x1,
            EWX_REBOOT = 0x2,
            EWX_FORCE = 0x4,
            EWX_POWEROFF = 0x8,
            EWX_FORCEIFHUNG = 0x10,
            EWX_RESTARTAPPS = 0x40
        }
    }
}
